package lab2;

import java.lang.reflect.InvocationTargetException;

public class Helper{
    public static AbstractFactory getFactory(String str){
        //默认Tensorflow
        AbstractFactory factory = TensorflowFactory.getInstance();
        try {
            factory = (AbstractFactory) Class.forName("lab2."+str+"Factory")
                    .getDeclaredMethod("getInstance",null)
                    .invoke(null,null);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }finally {
            return factory;
        }
    }
}
